{% extends 'base_backend.html' %}
{% load static %}
{% load my_filter %}

{% block header_tail %}
    <link rel="stylesheet" href="{% static 'zhongbao/zhongbao_admin/css/style.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/zhongbao_admin/css/iconfont.css' %}">
    <link rel="stylesheet" href="{% static 'plugins/datatables/dataTables.bootstrap.css' %}">
    <link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/config/css/main.css' %}">
    <link rel="stylesheet" href="{% static 'laydate/theme/default/laydate.css' %}">
    <script src="{% static 'laydate/laydate.js' %}"></script>
    <script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>
    <script src="{% static 'plugins/vue1/vue.js' %}"></script>
    <script src="{% static 'plugins/jQuery/jquery-2.2.3.min.js' %}"></script>
    <script src="{% static 'plugins/vue1/vue.js' %}"></script>
    <style>
        .login-banner {
            width: 100%;
            background: url("{% static 'public/img/banner2.jpg' %}") center bottom/cover no-repeat;
        }
    </style>
{% endblock header_tail %}

{% block section_content %}
    <div class="row" id="nav-app">
        {% if is_agent %}
            <div class="col-lg-4 col-xs-4">
                <div class="small-box bg-aqua">
                    <div class="inner">
                        <p>所有项目</p>
                        <h3 id="acceptProject">{{ all_project_num }}</h3>
                    </div>
                    <div class="icon">
                        <!--<i class="glyphicon glyphicon-star-empty"></i>-->
                        <i class="fa fa-coffee" style="margin-top: 15px;"></i>
                    </div>
                    <a href="{% url 'task:manage_agent' 'project' %}" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
            <div class="col-lg-4 col-xs-4">
                <div class="small-box bg-red">
                    <div class="inner">
                        <p>处理中项目</p>
                        <h3 id="acceptProject">{{ acc_project_num }}</h3>
                    </div>
                    <div class="icon">
                        <!--<i class="glyphicon glyphicon-star-empty"></i>-->
                        <i class="fa fa-sitemap" style="margin-top: 15px;"></i>
                    </div>
                    <a href="{% url 'task:manage_agent' 'project' %}?status=3" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
            <div class="col-lg-4 col-xs-4">
                <div class="small-box bg-green">
                    <div class="inner">
                        <p>已结算项目</p>
                        <h3 id="myProject">{{ pas_project_num }}</h3>
                    </div>
                    <div class="icon" style="margin-top: 15px;">
                        <i class="fa fa-bell"></i>
                    </div>
                    <a href="{% url 'task:manage_agent' 'project' %}?status=4" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
        {% endif %}
        {% if not is_agent %}
            <div class="col-lg-3 col-xs-4">
                <div class="small-box bg-aqua">
                    <div class="inner">
                        <p>所有项目</p>
                        <h3 id="acceptProject">{{ all_project_num }}</h3>
                    </div>
                    <div class="icon">
                        <!--<i class="glyphicon glyphicon-star-empty"></i>-->
                        <i class="fa fa-coffee" style="margin-top: 15px;"></i>
                    </div>
                    <a href="{% url 'task:manage' 'project' %}" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
            <div class="col-lg-3 col-xs-4">
                <div class="small-box bg-green">
                    <div class="inner">
                        <p>未分配项目</p>
                        <h3 id="myProject">{{ unallocated_project_num }}</h3>
                    </div>
                    <div class="icon" style="margin-top: 15px;">
                        <i class="fa fa-bell"></i>
                    </div>
                    <a href="{% url 'task:manage' 'project' %}?status=2" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
            <div class="col-lg-3 col-xs-4">
                <div class="small-box bg-red">
                    <div class="inner">
                        <p>处理中项目</p>
                        <h3 id="acceptProject">{{ acc_project_num }}</h3>
                    </div>
                    <div class="icon">
                        <!--<i class="glyphicon glyphicon-star-empty"></i>-->
                        <i class="fa fa-sitemap" style="margin-top: 15px;"></i>
                    </div>
                    <a href="{% url 'task:manage' 'project' %}?status=3" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
            <div class="col-lg-3 col-xs-4">
                <div class="small-box bg-green">
                    <div class="inner">
                        <p>已结算项目</p>
                        <h3 id="myProject">{{ pas_project_num }}</h3>
                    </div>
                    <div class="icon" style="margin-top: 15px;">
                        <i class="fa fa-bell"></i>
                    </div>
                    <a href="{% url 'task:manage' 'project' %}?status=4" class="small-box-footer">
                        详情&nbsp;
                        <i class="fa fa-arrow-circle-right"></i>
                    </a>
                </div>
            </div>
        {% endif %}
    </div>
    <div>
        <div class="box-header with-border">
            <h3 class="box-title">{{ model_verbose_name }}</h3>
        </div>
        <!-- form start -->
        <div class="box box-primary">
            <div class="box-header with-border" style="border-color: #1b6d85">
                <!-- Date range -->
                <form role="form" id="searchForm">
                    <input class="no-display" type="text">
                    <p style="clear: both"></p>
                    <div style="width: 90%; float: left;">
                        {% for field in form %}
                            <div class="input-group select-config-div" style="float: left; ">
                                <label for="" class="control-label">{{ field.label }}：</label>
                                <p>{{ field }}</p>
                            </div>
                        {% endfor %}
                    </div>
                    <div class="input-group" style="width: 5%; float: right;">
                        <input type="text" class="no-display">
                        <span id="searchBtn" onclick="searchProject()"
                              class="form-control pull-left btn btn-sm btn-primary"
                              style="margin-top:20px;width: 50px">检索
                        </span>
                    </div>
                    <p style="clear: both"></p>
                    <div class="form-group">
                    </div>
                </form>
            </div>

            <!-- 展示搜索出来的任务 -->
            <div id="main">
                <div id="showMessage" v-show="message"> [[ message ]]</div>
                <div class="box-body" v-show="showMain">
                    <form id="model_form" role="form"
                          method="post">{% csrf_token %}
                        <div class="group">
                            <span v-show="project_settlement_count">共完成[[ project_settlement_count ]]个总计[[summaryAmount]]元</span>
                            <span v-show="all_summaryAmount">总计[[all_summaryAmount]]元</span>
                            <table id="task_each_table" border="1"
                                   class="table table-bordered table-hover table-striped">
                                <thead>
                                <tr>
                                    <th v-for="head in tableData.headers">
                                        <span style="float: left">
                                            [[ head.name ]]
                                        </span>
                                        {% if field.rank %}
                                            <a href="?[[ head.rank ]]=[[ head.rank_tag ]][[ page_args ]]"
                                               style="float: right">
                                                {% if field.rank_tag == 0 %}
                                                    <i class="fa fa-fw fa-sort"></i>
                                                {% elif field.rank_tag == 1 %}
                                                    <i class="fa fa-fw fa-sort-numeric-asc"></i>
                                                {% elif field.rank_tag == -1 %}
                                                    <i class="fa fa-fw fa-sort-numeric-desc"></i>
                                                {% endif %}
                                            </a>
                                        {% endif %}
                                    </th>
                                    <th>
                                        {% if not query_project_id %}
                                            <span style="float: left">
                                                操作
                                            </span>
                                        {% endif %}
                                    </th>
                                </tr>

                                </thead>
                                <tbody>
                                {% if query_project_id %}
                                    <tr v-if="tableData.tasks == '' ">
                                        <td>没有用户完成！</td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                    <template v-for="task in tableData.tasks">
                                        <tr>
                                            <template v-for="head in tableData.headers">
                                                <template
                                                        v-if="head.key == 'username'|| head.key == 'real_name' || head.key == 'alipay_count' || head.key == 'project_settlement_count'|| head.key == 'settlement_count'|| head.key == 'proportion'">
                                                    <td>[[ task[head.key] ]]</td>
                                                </template>
                                            </template>
                                        </tr>
                                    </template>
                                {% endif %}
                                {% if not query_project_id %}
                                    <tr v-if="tableData.tasks == '' ">
                                        <td>暂无项目</td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                    <template v-for="task in tableData.tasks">
                                        <tr>
                                            <template v-for="head in tableData.headers">
                                                <template
                                                        v-if="head.key == 'deadline_flag'|| head.key == 'finish_flag' || head.key == 'ctime' || head.key == 'status' || head.key == 'project_quality_flag'">
                                                    <td v-if="head.key == 'status'">[[ parseStatus(task[head.key]) ]]
                                                    </td>
                                                    <td v-else>[[ parseTime(task[head.key]) ]]</td>
                                                </template>
                                                <template v-else>
                                                    <td v-if="head.key == 'status_progress' || head.key == 'adopt_progress'">
                                                        <div class="progress active">
                                                            <div class="progress-bar progress-bar-success progress-bar-striped"
                                                                 role="progressbar" aria-valuenow="20" aria-valuemin="0"
                                                                 aria-valuemax="100">
                                                                {% if head.key == '100%' %}
                                                                    <span style="color: black;">已完成</span>
                                                                {% else %}
                                                                    <span style="color: black;">[[ task[head.key] ]]</span>
                                                                {% endif %}
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td v-else>[[ task[head.key] ]]</td>
                                                </template>
                                            </template>
                                            <td class="btn-group">
                                                <!--<button v-if="task.status == 1" type="button" value="[[ task.id ]]" class="btn btn-info btn-xs" onclick="operation([[task.id]])">操作</button>-->
                                                <button type="button" value="[[ task.project_id ]]"
                                                        class="btn btn-info btn-xs"
                                                        onclick="detailOneTask([[task.project_id]])">详情
                                                </button>
                                                <button v-if="task.spot_check == 1" type="button"
                                                        class="btn btn-info btn-xs"
                                                        onclick="Sampling_results([[task.project_id]])">抽查结果
                                                </button>
                                                {% if status == 4 %}
                                                    <button type="button" class="btn btn-info btn-xs"
                                                            onclick="_SettlementDetails([[task.project_id]])">结算详情
                                                    </button>
                                                {% endif %}
                                                {% if status != 4 %}
                                                    <button v-if=" task.agency_id " type="button" value="[[ task.id ]]"
                                                            class="btn btn-info btn-xs"
                                                            onclick="_taskAllocation([[task.project_id]])">任务分配
                                                    </button>
                                                {% endif %}
                                                {% if user.is_superuser %}
                                                    <button type="button" class="btn btn-info btn-xs"
                                                            onclick="_project_warehousy([[task.project_id]])">优先入库
                                                    </button>
                                                    <button v-if="task.project_settlement == 0" type="button"
                                                            class="btn btn-info btn-xs"
                                                            onclick="spotCheck([[task.project_id]])">抽查
                                                    </button>
                                                    <button v-if=" ! task.agency_id " type="button"
                                                            value="[[ task.id ]]" class="btn btn-info btn-xs"
                                                            onclick="_distribution([[task.project_id]])">项目分配
                                                    </button>
                                                    <button v-if="task.project_settlement == 0" type="button"
                                                            class="btn btn-info btn-xs"
                                                            onclick="_atchbSynchronization([[task.project_id]])">批量同步
                                                    </button>
                                                    {% if user.id == 489 or user.id == 132 or user.id == 135 or user.id == 504 %}
                                                        <button v-if="task.project_settlement == 0" type="button"
                                                                class="btn btn-info btn-xs"
                                                                onclick="_allAdopt([[task.project_id]])">全部通过
                                                        </button>
                                                        <button v-if="task.project_settlement == 0" type="button"
                                                                class="btn btn-info btn-xs"
                                                                onclick="_settlement([[task.project_id]])">项目结算
                                                        </button>
                                                    {% endif %}
                                                    <button type="button" class="btn btn-info btn-xs"
                                                            onclick="_priority_sync([[task.project_id]])">优先同步
                                                    </button>
                                                {% endif %}
                                                <a href="{% url 'task:export_project_report' %}?project_id=[[task.project_id]]"
                                                   class="btn btn-info btn-xs">导出项目详情</a>
                                            </td>
                                        </tr>
                                    </template>
                                {% endif %}
                                </tbody>
                            </table>
                            <p class="" id="paginator">
                                <a class="btn btn-default btn-xs" v-if="paginator.current > 1"
                                   onclick="toPage('first',paginator.limit)">首页</a>
                                <a class="btn btn-default btn-xs" v-else disabled="true">首页</a>
                                <a class="btn btn-default btn-xs" v-if="paginator.current > 1"
                                   onclick="toPage('prev',paginator.limit)">上一页</a>
                                Page [[ paginator.current ]] of [[ paginator.last ]]
                                <a class="btn btn-default btn-xs" v-if="paginator.current < paginator.last"
                                   onclick="toPage('next',paginator.limit)">下一页</a>
                                <a class="btn btn-default btn-xs" v-if="paginator.current < paginator.last"
                                   onclick="toPage('last',paginator.limit)">尾页</a>
                                <a class="btn btn-default btn-xs" v-else disabled="true">尾页</a>
                                <input type="text" id="page-judge" style="width: 30px;height:20px; margin-left: 20px"
                                       onkeyup="toPage('judge', paginator.limit)">
                                <a class="btn btn-default btn-xs" onclick="toPage('judge', paginator.limit)">跳页</a>
                            </p>
                        </div>
                        <!-- /.box-footer -->
                        <div class="box-footer">
                            <button class="btn btn-primary no-display" id="submit_button">确认</button>
                            <button type="button" class="btn btn-primary" id="save_submit" name="_save"
                                    style="display: none">sure
                            </button>
                        </div>
                    </form>
                </div>

                <!--弹出操作提示消息-->
                <div class="modal fade" id="submit_spot_checks" tabindex="-1" role="dialog"
                     aria-labelledby="myModalLabel" style="top:40%">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                                <label>抽查结果：</label>
                            </div>
                            <div v-for="submitSpot in submit_spot_checks_list" id="msgBoxMsg" class="modal-body">
                                <div style="border: 1px solid #BBBBBB;">
                                    <div style="overflow:auto;text-align:center;border-bottom: 1px solid #BBBBBB;">
                                        <span>[[ submitSpot.sampling_title ]]</span>
                                    </div>
                                    <div style="overflow:auto;border-right: 1px solid #BBBBBB;width: 50%;float:left;padding-left: 40px">
                                        <div v-for="describe in submitSpot.describe">[[ describe ]]</div>
                                    </div>
                                    <div style="overflow:auto;width: 50%;float:left;border-left: 1px solid #BBBBBB;">
                                        <div style="padding-left: 20px">错误任务ID:</div>
                                        <a v-for="id in submitSpot.id"
                                           style="padding-left: 20px;color: red;cursor:pointer"
                                           onclick="tiaozhuan('[[ id ]]')"> [[ id ]]</a>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer" style="text-align:center;">
                                <button type="button" class="btn btn-default" data-dismiss="modal">确认
                                </button>
                                <button type="button" class="btn btn-default"
                                        data-dismiss="modal">返回
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

    <div class="modal fade" id="userList" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:30%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body" style="overflow:auto">
                    <label>请选择要分配给谁（可以多选）：</label>
                    <!--
                    {/% for user in configUsers %}
                        <br><input name="user" type="radio" value="{/{ user.id }}">
                        <label>{/{ user.user.username }}</label>
                    {/% endfor %}
                    -->
                    <table id="user_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th class="action-checkbox">
                                <input type="checkbox" name="uth_checkbox" onclick="_checkAll(this)">
                            </th>
                            <th>
                                    <span style="float: left">
                                        用户名
                                    </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for user in configUsers %}
                            <br>
                            <tr>
                                <td class="action-checkbox">
                                    <input type="checkbox" name="utd_checkbox" value="{{ user.user.id }}"
                                           onclick="_checkOne(this)">
                                </td>
                                <td>{{ user.user.username }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" id="confirm_close" class="btn btn-default"
                            data-dismiss="modal" onclick="confirmClose()">确认
                    </button>
                    <button type="button" id="cancel_close" class="btn btn-default"
                            data-dismiss="modal" onclick="cancelClose()">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    {#    分配项目#}
    <div class="modal fade" id="distribution" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:20%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body" style="overflow:auto">
                    <label>请选择要分配给谁：</label>
                    <table id="user_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th>
                                    <span style="float: left">
                                        代理名
                                    </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody id='aaa'>
                        {% for agency in Agencys %}
                            <br>
                            <tr>
                                <td class="action-checkbox">
                                    <input type="radio" name="utd_checkbox" value="{{ agency.id }}"
                                           onclick="_checkOne(this)">
                                </td>
                                <td>{{ agency.agent_name }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" id="confirm_close" class="btn btn-default"
                            data-dismiss="modal" onclick="confirmClose()">确认
                    </button>
                    <button type="button" id="cancel_close" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    {#    结算#}
    <div class="modal fade" id="settlement" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要结算吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="settlement()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>


    {#    批量同步#}
    <div class="modal fade" id="atchbSynchronization" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要全部同步吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="atchbSynchronization()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    {#    批量同步#}
    <div class="modal fade" id="project_warehousy" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要置顶优先入库吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="project_warehousy()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>


    {#    全部通过#}
    <div class="modal fade" id="allAdopt" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要全部通过吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="allAdopt()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--弹出提示消息-->
    <div class="modal fade" id="taskMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    请选择代理！
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">确认
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="taskMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    请至少选择一个状态！
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">确认
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="retrieveMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要回收吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="retrieve()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出操作提示消息-->
    <div class="modal fade" id="operationMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请选择反馈原因，无需反馈则直接点击领取</label>
                </div>

                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    <table id="operation_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <tbody>
                        <tr>
                            <td class="action-checkbox">
                                <input type="radio" name="utd_checkbox" value="网站失效" onclick="_checkOne(this)">
                            </td>
                            <td>网站失效，无法打开</td>
                        </tr>
                        <tr>
                            <td class="action-checkbox">
                                <input type="radio" name="utd_checkbox" value="网站难度较大" onclick="_checkOne(this)">
                            </td>
                            <td>网站难度较大</td>
                        </tr>
                        <tr>
                            <td class="action-checkbox">
                                <input type="radio" name="utd_checkbox" value="领取" onclick="_checkOne(this)">
                            </td>
                            <td>确认领取</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="confirmClose()"
                            data-dismiss="modal">确认
                    </button>
                    {#                     <button type="button"class="btn btn-default" onclick="op_appect()"#}
                    {#                            data-dismiss="modal">领取#}
                    {#                    </button>#}
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="passMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要判定为合格状态吗？
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="pass()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="rejectMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要判定为不合格状态吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="reject()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="revokeMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要修改为不合格状态吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="revoke()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="checkMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要修改为已合格状态吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="check()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--同步优先级信息-->
    <div class="modal fade" id="priority_message" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body" style="overflow:auto;text-align:center;">
                    目前各优先级配置数量：
                    <template v-for="grade in grade_info">
                        <p>[[ grade.grade ]]级：[[ grade.num ]]个</p>
                    </template>
                    <p>请设置优先级</p>
                    <input type="number" name="grade" id="grade">
                    <input type="hidden" name="project_id" id="project_id" value="">
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="priority_sync()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <input id="taskIds" value="" style="display:none;"></input>

    <script>
        var uid = '{{ uid }}';

        function _checkOne(obj) {
            if ($("input[name='uth_checkbox']").is(":checked")) {
                $("input[name='uth_checkbox']").prop("checked", false)
            } else {
                var unChecked = 0;
                $("input[name='utd_checkbox']").each(
                    function () {
                        if ($(this).is(":checked")) {

                        } else {
                            unChecked += 1
                        }
                    }
                );
                if (unChecked === 0) {
                    $("input[name='uth_checkbox']").prop("checked", true)
                }
            }
        }


        function operation(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#operationMessage").modal();
            } else {
                return false
            }
        }

        function op_appect(tids) {
            if (!tids) {
                tids = $("#taskIds").val()
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                accept(tids)
            }
            $("#taskIds").val("");
        }

        function confirmClose() {
            var agency_id = '';
            var project_id = '';
            $("input[name='utd_checkbox']:checked").each(
                function () {
                    agency_id = $(this).val();
                    project_id = $('#aaa').attr('project_id')
                }
            );
            if (agency_id === '') {
                $("#taskMessage").modal();
                return false
            } else if (project_id === '') {
                alert('获取项目失败！');
            } else {
                var searchForm = 'agency_id=' + agency_id + '&project_id=' + project_id;
                $.get(
                    "{% url 'task:distribution_project' %}",
                    searchForm,
                    function (response) {
                        if (response) {
                            if (response.message == '分配成功！') {
                                if (confirm(response.message) == true) {
                                    window.location.href = window.location.href;
                                }
                            }
                        } else {
                            alert(response.message)
                        }
                    }
                )
            }

            {#uids = userIds.join();#}

            {#allocate(tids, uids);#}
            _clearChecked();
        }

        function _clearChecked() {
            if ($("input[name='uth_checkbox']").is(":checked")) {
                $("input[name='uth_checkbox']").prop("checked", false)
            }
            $("input[name='utd_checkbox']:checked").each(
                function () {
                    $(this).prop("checked", false);
                }
            );
        }

        function opera(tids, cvalue) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                return false
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids,
                        cvalue: cvalue

                    }
                });
                $.post(
                    "{% url 'task:accept' %}",
                    function (response) {
                        alert(response.message);
                        mainVue.message = response.message;
                        toPage('current')
                    }
                )
            }
        }


        function acceptOneTask(tids) {
            accept(tids)
        }

        function accept(tids, cvalue) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                return false
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids,
                        cvalue: cvalue
                    }
                });
                $.post(
                    "{% url 'task:accept' %}",
                    function (response) {
                        alert(response.message);
                        mainVue.message = response.message;
                        toPage('current')
                    }
                )
            }
        }

        function detailOneTask(pid) {
            {% if is_agent %}
                var url = "{% url 'task:project_detail_agent' model_DOM_id %}" + "?pid=" + pid;
            {% endif %}
            {% if not is_agent %}
                var url = "{% url 'task:project_detail' model_DOM_id %}" + "?pid=" + pid;
            {% endif %}
            window.location.href = url;
        }

        Vue.config.delimiters = ["[[", "]]"];


        function toPage(page) {
            if (mainVue.paginator) {
                if (page == 'current') {
                    page = mainVue.paginator.current
                }
                if (page == 'next') {
                    page = mainVue.paginator.current + 1
                }
                if (page == 'prev') {
                    page = mainVue.paginator.current - 1
                }
                if (page == 'first') {
                    page = 1
                }
                if (page == 'last') {
                    page = mainVue.paginator.last
                }
                if (page == 'judge') {
                    page = $("#page-judge").val();
                }
                if (page < 1) {
                    page = 1;
                }
                if (page > mainVue.paginator.last) {
                    page = mainVue.paginator.last;
                }
                if (page < mainVue.paginator.first) {
                    page = mainVue.paginator.first;
                }
            } else {
                page = 1;
            }
            mainVue.page = page;
            render(mainVue);
        }

        function render(obj) {
            var searchForm = obj.searchForm + '&page=' + obj.page;
            {% if agency_id %}
                searchForm = searchForm + "&agency_id=" + '{{ agency_id }}'
            {% endif %}
            $.get(
                "{% url 'task:show_projects' %}",
                searchForm,
                function (response) {
                    if (response) {
                        obj.showMain = true;
                        obj.tableData = response.tableData;
                        obj.paginator = response.paginator;
                        obj.message = response.message;
                        console.log(obj.paginator);
                    } else {
                        obj.showMain = false;
                    }
                }
            )
        }

        var mainVue = new Vue({
            el: "#main",
            data: {
                page: 1,
                status: 1,
                limit: {{ limit }},
                searchForm: "",
                checkedAll: false,
                showMain: false,
                tableData: {},
                paginator: {},
                message: "",
                submit_spot_checks_list: [],
            },
            methods: {
                parseTime: function (timeStamp) {
                    console.log(timeStamp)
                    if (!timeStamp) {
                        return ""
                    }
                    var newDate = new Date();
                    newDate.setTime(timeStamp * 1000);
                    return newDate.toLocaleDateString()
                },
                parsePer: function (num1, num2) {
                    var newDate = new Date();
                    newDate.setTime(timeStamp * 1000);
                    return newDate.toLocaleDateString()
                },
                parseStatus: function (status) {
                    var statuses = {
                        1: {
                            name: "待分配"
                        },
                        2: {
                            name: "待处理"
                        },
                        3: {
                            name: "处理中"
                        },
                        4: {
                            name: "待审核"
                        },
                        5: {
                            name: "已合格"
                        },
                        6: {
                            name: "不合格"
                        },
                        0: {
                            name: "已回收"
                        }
                    };
                    return statuses[status]["name"]
                },
                //searchTasks: searchTasks,
                getTasks: function () {
                    var searchForm = 'page=' + this.page + '&limit=' + this.limit + '&status=' + this.status;
                    {% if agency_id %}
                        searchForm = searchForm + "&agency_id=" + '{{ agency_id }}'
                    {% endif %}
                    $.get(
                        "{% url 'task:show_projects' %}",
                        searchForm,
                        function (response) {
                            if (response) {
                                this.showMain = true;
                                this.tableData = response.tableData;
                                this.paginator = response.paginator;
                                this.message = response.message;
                                console.log(this.paginator);
                            } else {
                                this.showMain = false;
                            }
                        }
                    )
                }
            },
            watch: {
                {#                page: function(){#}
                {#                    render(this);#}
                {#                }#}
            }
        });

        function searchProject() {
            {% if model_DOM_id == 'manage' %}
                {% if not status %}
                    mainVue.searchForm = $("#searchForm").serialize() + "&limit=10&type=manage";
                {% else %}
                    mainVue.searchForm = $("#searchForm").serialize() + "&status={{ status }}&limit=10&type=manage";
                {% endif %}
                {% if agency_id %}

                    mainVue.searchForm = mainVue.searchForm + "&agency_id=" + '{{ agency_id }}'
                {% endif %}
                {% if query_project_id %}
                    mainVue.searchForm = mainVue.searchForm + "&query_project_id=" + '{{ query_project_id }}'
                {% endif %}
            {% else %}
                if (uid) {
                    mainVue.searchForm = $("#searchForm").serialize() + "&limit=10&uid={{ uid }}";
                } else {
                    mainVue.searchForm = $("#searchForm").serialize() + "&limit=10";
                }
            {% endif %}
            $.get(
                "{% url 'task:show_projects' %}",
                mainVue.searchForm,
                function (response) {
                    if (response) {
                        mainVue.limit = response.limit;
                        mainVue.showMain = true;
                        mainVue.limits = response.limits;
                        mainVue.tableData = response.tableData;
                        mainVue.paginator = response.paginator;
                        mainVue.message = response.message;
                    } else {
                        mainVue.showMain = false;
                    }
                }
            )
        }

        searchProject();

        {# 全部通过 #}

        function _allAdopt(project_id) {
            $("#taskIds").val(project_id);
            $('#allAdopt').modal()
        }

        function allAdopt() {
            project_id = $("#taskIds").val();
            $("#taskIds").val("");
            if (project_id) {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        project_id: project_id,
                    }
                });
                $.post(
                    "{% url 'task:adopt' %}",
                    function (response) {
                        var msg = response.message;
                        if (msg) {
                            alert(msg);
                        }
                        window.location.href = window.location.href
                    }
                )
            }
        }

        {#结算#}

        function _settlement(project_id) {
            $("#taskIds").val(project_id);
            $('#settlement').modal()
        }

        function settlement() {
            project_id = $("#taskIds").val();
            $("#taskIds").val("");
            if (project_id) {
                ss = "project_id=" + String(project_id)
                $.get(
                    "{% url 'task:projects_settlement' %}",
                    ss,
                    function (response) {
                        if (response) {
                            alert(response)
                            window.location.href = window.location.href
                        } else {
                            alert('结算失败！');
                        }
                    }
                )
            }

        }

        {#结算详情#}

        function _SettlementDetails(project_id) {
            if (project_id) {
                {% if is_agent %}
                    ss = "?project_id=" + String(project_id) + '&status=' + '5'
                    window.location.href = "{% url 'task:manage_agent' 'project' %}" + ss
                {% endif %}
                {% if not is_agent %}
                    ss = "?project_id=" + String(project_id) + '&status=' + '5'
                    window.location.href = "{% url 'task:manage' 'project' %}" + ss
                {% endif %}
            } else {
                alert('无法获取当前项目！')
            }
        }

        function spotCheck(project_id) {
            if (project_id) {
                {% if user.is_superuser %}
                    window.location.href = "{% url 'task:task_audit'%}" + '?' + 'project_id' + '=' + project_id
                {% endif %}
            }
        }


        function _distribution(project_id) {
            $('#aaa').attr('project_id', project_id);
            $('#distribution').modal()
        }

        function _taskAllocation(project_id) {
            window.open("{% url 'task:manage_agent' 'task' %}" + '?status=1' + '&project_id=' + project_id)
        }

        function Sampling_results(project_id) {
            $.ajax({
                type: "POST",
                url: "{% url 'task:sampling_results' %}",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    project_id: project_id,
                },
                success: function (response) {
                    if (response.message == 'ok') {
                        mainVue.submit_spot_checks_list = response.submit_spot_checks_list
                        $('#submit_spot_checks').modal();
                    } else {
                        alert('提交出错！')
                    }
                }
            })
        }

        function _atchbSynchronization(project_id) {
            $("#taskIds").val(project_id);
            $('#atchbSynchronization').modal()
        }

        function atchbSynchronization() {
            project_id = $("#taskIds").val();
            $("#taskIds").val("");
            $.ajax({
                type: "POST",
                url: "{% url 'task:atchb_synchronization' %}",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    project_id: project_id,
                },
                success: function (response) {
                    alert(response.message)
                    toPage(response, -1)
                }
            })

        }

        function _project_warehousy(pid) {
            $("#taskIds").val(pid);
            $('#project_warehousy').modal()
        }

        function project_warehousy() {
            var project_id = $("#taskIds").val();
            $("#taskIds").val("");
            $.ajax({
                type: "POST",
                url: "{% url 'task:project_warehousy' %}",
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    project_id: project_id,
                },
                success: function (response) {
                    alert(response.message)
                    toPage(response, -1)

                }
            })
        }

        function tiaozhuan(tid) {
            window.open('{% url 'task:detail' %}' + '?id=' + tid + '&type=task&user=admin')
        }

        function changeColor(id, color) {
            //$(id).parent().parent().parent().children().children().children().find("li[color='green']");
            $(id).parent().parent().addClass("active");
            $(id).children().css("color", color);
        }

        //$("#taskManager").addClass("active");

        if ('{{ is_agent }}' === '1') {
            changeColor("#{{ model_DOM_id }}_project_agent", "#00FF7F");
        } else {
            changeColor("#{{ model_DOM_id }}_project", "#00FF7F");
        }
        $('#nav_project').addClass("active");
        // 时间控件
        laydate.render({
            elem: '#test1',
            range: true
        });
        laydate.render({
            elem: '#test2'
            , range: true
        });
        laydate.render({
            elem: '#test3'
            , range: true
        });
        laydate.render({
            elem: '#test4'
            , range: true
        });
        laydate.render({
            elem: '#test5'
            , range: true
        });
    </script>
<script>
    var PriorityVue = new Vue({
        el: '#priority_message',
        data: {
            grade_info: []
        }
    });
    function _priority_sync(project_id) {
         $.ajax({
             type: "POST",
             url: "{% url 'task:get_priority_sync_num' %}",
             data:{
                 csrfmiddlewaretoken:'{{ csrf_token }}',
             },
             success: function(response) {
                 $('#project_id').val(project_id);
                 PriorityVue.grade_info = response.grade_info;
                 $('#priority_message').modal();
              }
         })
    }
    function priority_sync() {
        var grade = $('#grade').val();
        var project_id = $('#project_id').val();
        if (!project_id || grade < 1 || grade > 5){
            return false
        }
         $.ajax({
             type: "POST",
             url: "{% url 'task:set_priority_sync' %}",
             data:{
                 project_id: project_id,
                 grade: grade,
                 csrfmiddlewaretoken:'{{ csrf_token }}',
             },
             success: function(response) {
                 alert(response.message);
              }
         })
    }
</script>
{% endblock section_content %}
                                                                                                                                                                                                                                                                                                                                                                                   